﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.WebApiTool
{
    public class DData
    {
        public List<DScenario> ScenarioList { get; set; }

        public List<Assembly> AssemblyList { get; set; }

        public DData()
        {
            ScenarioList = new List<DScenario>();

            AssemblyList = new List<Assembly>();
        }

        public void AddAssembly(Assembly assembly)
        {
            bool isExist = false;
            foreach (var item in AssemblyList)
            {
                if(item == assembly)
                {
                    isExist = true;
                    break;
                }
            }

            if(!isExist)
            {
                AssemblyList.Add(assembly);
            }
        }

        public bool Exist(string scenarioName)
        {
            for (int index = 0; index < ScenarioList.Count; index++)
            {
                if(string.Equals(scenarioName, ScenarioList[index].Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }

        public DScenario Get(string scenarioName)
        {
            for (int index = 0; index < ScenarioList.Count; index++)
            {
                if (string.Equals(scenarioName, ScenarioList[index].Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    return ScenarioList[index];
                }
            }
            return null;
        }


        public DScenario Add(string snoName)
        {
            DScenario scenario = new DScenario(snoName);
            ScenarioList.Add(scenario);

            return scenario;
        }

        /// <summary>
        /// 排序
        /// </summary>
        public void Sort()
        {
            ScenarioList = ScenarioList.OrderBy(p => p.Name).ToList();

            foreach (var scenario in ScenarioList)
            {
                scenario.Actions = scenario.Actions.OrderBy(p => p.Name).ToList();
            }
        }
    }
}
